/************************************************************
 * Project Name		[Thinking_In_Java]
 * File Name     	[pkg_algorithm.Triangle.java]
 * Creation Date 	[14-Jun-2014]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ************************************************************/
package pkg_algorithm;

import java.util.Scanner;

/**
 * 打印各种类型的三角形
 * 
 * @author 不落的太阳(Sean Yang)
 * @version 1.0
 * @since JDK 6
 * 
 */
public class Triangle {

	/**
	 * 打印直角三角形
	 * 
	 * @param k
	 *            三角形高度(行数)
	 */
	public static void shape1(int k) {
		for (int i = 0; i < k; i++) {
			for (int j = 0; j <= i; j++) {
				System.out.print('*');
			}
			System.out.println();
		}
	}

	/**
	 * 打印倒直角三角形
	 * 
	 * @param k
	 *            三角形的高度(行数)
	 */
	public static void shape2(int k) {
		for (int i = 0; i < k; i++) {
			for (int j = k; j > i; j--) {
				System.out.print('*');
			}
			System.out.println();
		}
	}

	/**
	 * 打印等腰三角形
	 * 
	 * @param n
	 *            三角形的行数
	 */
	public static void shape3(int n) {

		for (int i = 1; i <= n; i++) {
			for (int j = n - i; j >= 0; j--) {
				System.out.print(' ');
			}
			for (int k = 1; k <= (2 * i - 1); k++) {
				System.out.print('*');
			}
			System.out.println("");
		}
	}

	/**
	 * 打印实心菱形
	 * 
	 * @param n
	 *            菱形的行数
	 */
	public static void shape4(int n) {

		for (int i = 0; i < n; i++) {
			for (int k = n - i; k > 0; k--) {
				System.out.print(' ');
			}
			for (int j = 1; j <= (2 * i + 1); j++) {
				System.out.print('*');
			}
			System.out.println();
		}
		for (int i = n - 1; i > 0; i--) {
			for (int k = 0; k <= n - i; k++) {
				System.out.print(' ');
			}
			for (int k = (2 * i); k > 1; k--) {
				System.out.print('*');
			}
			System.out.println();
		}

	}

	/**
	 * 打印空心菱形
	 * 
	 * @param n
	 *            菱形行数
	 */
	public static void shape5(int n) {

		for (int i = 0; i < n; i++) {
			for (int k = n - i; k > 0; k--) {
				System.out.print(' ');
			}
			System.out.print('*');
			for (int j = 1; j <= (2 * i - 1); j++) {
				System.out.print(' ');
			}
			if (i > 0) {
				System.out.print('*');
			}
			System.out.println();
		}
		for (int i = n - 1; i > 0; i--) {
			for (int k = 0; k <= n - i; k++) {
				System.out.print(' ');
			}
			System.out.print('*');
			for (int k = ((2 * i) - 1); k > 2; k--) {
				System.out.print(' ');
			}
			if (i > 1) {
				System.out.print('*');
			}
			System.out.println();
		}

	}

	/**
	 * 测试方法
	 * 
	 * @param args
	 *            命令行参数
	 */
	public static void main(String[] args) {
		System.out.println("请输入一个正整数");
		Scanner scanner = new Scanner(System.in);
		int i = scanner.nextInt();
		scanner.close();

		Triangle.shape1(i);
		System.out.println();
		Triangle.shape2(i);
		System.out.println();
		Triangle.shape3(i);
		System.out.println();
		Triangle.shape4(i);
		System.out.println();
		Triangle.shape5(i);
	}

}
